﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;

namespace Xejen.Database.SqlSugar
{
    /// <inheritdoc cref="IDbContextProvider{TDbContext}" path="/summary"/>
    public sealed class DbContextProvider<TDbContext> : IDbContextProvider<TDbContext>
        where TDbContext : SqlSugarClient
    {
        /// <inheritdoc/>
        public TDbContext DbContext { get; }

        /// <inheritdoc cref="DbContextProvider{TDbContext}"/>
        /// <param name="dbContext"><inheritdoc cref="DbContextProvider{TDbContext}.DbContext" path="/summary"/></param>
        public DbContextProvider(TDbContext dbContext)
        {
            DbContext = dbContext;
        }

        /// <inheritdoc/>
        public TDbContext GetDbContext()
        {
            return DbContext;
        }

        /// <inheritdoc/>
        public Task<TDbContext> GetDbContextAsync()
        {
            return Task.FromResult(DbContext);
        }
    }
}
